#include"share_test.h"

#define PATHNAME "."
#define PROJ_ID 0x6666

int main()
{
    if (mkfifo("name_pipe", 0666) == -1) perror("create name_pipe fail"), exit(0);
    
    int fd = open("name_pipe", O_RDWR | O_APPEND);
    if (fd < 0) perror("open name_pipe fail"), exit(0);

    key_t _key = ftok(PATHNAME, PROJ_ID);
    if (_key < 0) perror("get key fail"), exit(0);

    int shmid  = shmget(_key, 4096, IPC_CREAT|IPC_EXCL|0666);
    if (shmid < 0) perror("shmget fail"), exit(0);

    char *start = (char*)shmat(shmid, NULL, 0);
    
    for (int i = 0; i < 45; i++){
        
        char buff[4];
        read(fd, buff, sizeof(buff));
       

        if (strcmp(buff,"ok") == 0)
            printf("%s\n", start);
         sleep(1);
    }

    sleep(3);
    shmdt(start);
    int n = shmctl(shmid, IPC_RMID, NULL);
    if (n < 0) perror("destory share_memory fail");

    return 0;
}